﻿using fuzhu;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XXX.Common;

namespace XXX.Bo
{
    public class DataChuli
    {
        //获取分号之前的是存货版本,使用^ ^
        public static string getBanben(string cBanben)
        {
           if ( string.IsNullOrWhiteSpace(cBanben))
                {
                return cBanben;
            }
            if (CanShu.bfree1chai == "1")
            { //替换全角字符的；
                string newbanben = "";
                //更改成^
                cBanben = cBanben.Replace("；", ";");
                cBanben = cBanben.Replace(";", "^");
                string[] lst = cBanben.Split('^');



                if (lst.Length > 0)
                {
                    newbanben = lst[0];
                }
                else
                {
                    //没有分隔符合，返回当前
                    newbanben = cBanben;
                }
                return newbanben;
            }
            else
                return cBanben;


        }

        //获取新的部门编码
        public static string getNewDepCode(string cdepcode,string constr)
        {
            if (string.IsNullOrWhiteSpace(cdepcode))
            {
                return cdepcode;
            }
            string sql = string.Format(@"select  cDepCode,dDepEndDate,cDepMemo from department where cdepcode='{0}'", cdepcode);
            DataTable dt  = DbHelper2.ExecuteTable (sql, constr);
            if (dt.Rows.Count>0)
            {
                //有部门中止日期
                if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["dDepEndDate"])))
                {
                    string cdepmemo = DbHelper.GetDbString(dt.Rows[0]["cDepMemo"]);
                    if (!string.IsNullOrEmpty(cdepmemo))
                    {
                        return cdepmemo;
                    }

                }
            }
            return cdepcode;

        }

        //获取新的仓库编码，取仓库的备注
        public static string getNewWhCode(string cwhcode, string constr)
        {
            if (string.IsNullOrWhiteSpace(cwhcode))
            {
                return cwhcode;
            }
            string sql = string.Format(@"select cwhcode,cwhmemo from  warehouse where cwhcode='{0}'", cwhcode);
            DataTable dt = DbHelper2.ExecuteTable(sql, constr);
            if (dt.Rows.Count > 0)
            { 
                    string cdepmemo = DbHelper.GetDbString(dt.Rows[0]["cwhmemo"]);
                    if (!string.IsNullOrEmpty(cdepmemo))
                    {
                        return cdepmemo;
                    }
 
            }
            return cwhcode;

        }
    }
}
